package my.assistant.homecashmanager.account.domain;

import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import my.assistant.homecashmanager.account.dao.AccountDao;
import my.assistant.homecashmanager.account.data.AccountBank;
import my.assistant.homecashmanager.account.data.AccountBase;
import my.assistant.homecashmanager.account.data.AccountCash;
import my.assistant.homecashmanager.account.data.AccountDebt;

import org.assistant.common.exception.ImplementNotFoundException;
import org.assistant.common.utils.ClassUtils;

public class AccountDomainImpl implements AccountDomain {
	private AccountDao accountDao;

	public AccountDomainImpl() throws ImplementNotFoundException {
		this.accountDao = (AccountDao) ClassUtils
			.getInterfaceImplement(AccountDao.class);
	}

	public AccountBank createDefaultBashAccount(String userId, String homeId)
			throws SQLException {
		AccountBank accountBank = new AccountBank();

		accountBank.setId(UUID.randomUUID().toString());
		accountBank.setUserId(userId);
		accountBank.setHomeId(homeId);
		accountBank.setBankCode("");
		accountBank.setClientNo("");
		accountBank.setAccountNo("");
		accountBank.setCardNo("");
		accountBank.setBalance(new BigDecimal(0));
		accountBank.setLatestDealDate(new Date());
		accountBank.setStatus(true);
		accountBank.setCreater(userId);
		accountBank.setCreateDate(new Date());

		accountDao.insertAccount(accountBank);

		return accountBank;
	}

	public AccountCash createDefaultCashAccount(String userId, String homeId)
			throws SQLException {
		AccountCash accountCash = new AccountCash();

		accountCash.setId(UUID.randomUUID().toString());
		accountCash.setUserId(userId);
		accountCash.setHomeId(homeId);
		accountCash.setBalance(new BigDecimal(0));
		accountCash.setLatestDealDate(new Date());
		accountCash.setStatus(true);
		accountCash.setCreater(userId);
		accountCash.setCreateDate(new Date());

		accountDao.insertAccount(accountCash);

		return accountCash;
	}

	public AccountDebt createDefaultDebtAccount(String userId, String homeId)
			throws SQLException {
		AccountDebt accountDebt = new AccountDebt();

		accountDebt.setId(UUID.randomUUID().toString());
		accountDebt.setUserId(userId);
		accountDebt.setHomeId(homeId);
		accountDebt.setBalance(new BigDecimal(0));
		accountDebt.setLatestDealDate(new Date());
		accountDebt.setStatus(true);
		accountDebt.setCreater(userId);
		accountDebt.setCreateDate(new Date());

		accountDao.insertAccount(accountDebt);

		return accountDebt;
	}

	public List<AccountBase> getAccountBaseListByHome(String homeId)
			throws SQLException {
		return accountDao.getAccountBaseListByHome(homeId);
	}

	public List<AccountBase> getAccountBaseListByUser(String userId)
			throws SQLException {
		return accountDao.getAccountBaseListByUser(userId);
	}

	public void setAccountDao(AccountDao accountDao) {
		this.accountDao = accountDao;
	}

}
